home *** CD-ROM | disk | FTP | other *** search
/ DS-CD ROM 2 1993 August / DS CD-ROM 2.Ausgabe (August 1993).iso / programm / ds0257 / demo.exe / LONGINT.DEM < prev    next >
Text File  |  1992-02-16  |  11KB  |  465 lines

  1. ; ----------------------------
  2. ; LONGINT.DEM  - Demo für die Routinen in LONGINT.LIB
  3. ;
  4. ;                (c) Bernd Schemmer 1990 - 1992
  5. ;                Letzter Update: 15.02.1992
  6. ;
  7. ; Übersetzen:
  8. ;  A86 LONGINT.DEM DEMOS.INC TO LONGINT.COM
  9. ;
  10. ; Hinweis: Die Environment-Variable 'A86' muß den Dateinamen 'MACROS.MAC'
  11. ;          enthalten und die .LIB-Dateien müssen über die Datei A86.LIB
  12. ;          erreichbar sein.
  13. ;
  14. ; ----------------------------
  15.  
  16.          jmp start
  17.  
  18. logo db CR,LF
  19.      db 'LONGINT.DEM - Demo für die Routinen in LONGINT.LIB'
  20.      db CR,LF
  21.      db '--------------------------------------------------'
  22.      db CR,LF
  23.      db CR,LF
  24. GETLENGTH Logo
  25.  
  26. PROMPT1 db
  27.         db 'Bitte geben Sie die Rechenart ein (+,-,*,/,\,^  <CR> = '
  28. _opcode0 db                                                     '+,  X, <ESC> = Ende): '
  29. GETLENGTH Prompt1
  30.  
  31. PROMPT2 db
  32.         db CR,LF
  33.         db 'Rechenart: '
  34. _Opcode db 'A --> '
  35.         db 'Bitte geben Sie den ersten Operanden ein: '
  36. GETLENGTH Prompt2
  37.  
  38. PROMPT3 db
  39.         db 'Rechenart: '
  40. _Opcode1 db 'A --> '
  41.         db 'Bitte geben Sie den zweiten Operanden ein: '
  42. GETLENGTH Prompt3
  43.  
  44. ResultMSG db
  45.         db 'Das Ergebnis ist '
  46. Result  db '                             '
  47.         db CR,LF
  48. GETLENGTH ResultMSG
  49.  
  50. RestMSG db
  51.         db 'Der Rest ist '
  52. Rest    db '                             '
  53.         db CR,LF
  54. GETLENGTH RestMSG
  55.  
  56. Error1 db 'Falsche Eingabe! (Eingabe zu groß oder Syntax falsch)'
  57.        db CR,LF
  58. GETLENGTH Error1
  59.  
  60. Error2 db 'Fehler beim Rechnen!'
  61.        db CR,LF
  62. GETLENGTH Error2
  63.  
  64. Op1    db 255,256 dup 0
  65. Op2    db 255,256 dup 0
  66.  
  67. OpCode db '+'
  68.  
  69. ; ----------------------------
  70.  
  71. Start:
  72.          call ShowLogo        ; Logo ausgeben und Speicherblock verkleinern
  73.  
  74. l0:                           ; Opcode ermitteln
  75.          WRITE_STRING Prompt1
  76. l00:
  77.          mov ah,08h
  78.          int 021h
  79.          cmp al,CR
  80.          je >l10              ; alten Opcode nochmal benutzen
  81.          cmp al,ESC
  82.          if e mov al,'X'
  83.  
  84.          cmp al,'X'           ; Eingabe auswerten
  85.          if e jmp Ende        ; Ende
  86.          cmp al,'x'
  87.          if e jmp Ende
  88.          cmp al,'^'
  89.          je >l1
  90.          cmp al,'+'
  91.          je >l1
  92.          cmp al,'-'
  93.          je >l1
  94.          cmp al,'*'
  95.          je >l1
  96.          cmp al,'\'
  97.          je >l1
  98.          cmp al,'/'
  99.          jne l00              ; Falsche Eingabe
  100. l1:
  101.          mov Opcode,al        ; Op-Code sichern
  102.          mov _Opcode,al       ; Op-Code in Meldungen eintragen
  103.          mov _Opcode0,al
  104.          mov _Opcode1,al
  105. l10:
  106.          call ShowCR_LF
  107.  
  108. l00:                          ; ersten Operanden lesen
  109.          WRITE_STRING Prompt2
  110.          mov dx,offset op1
  111.          mov ah,0Ah
  112.          int 021h
  113.          call ShowCR_LF
  114.  
  115.          mov si,offset op1+2  ; Eingabe konvertieren
  116.          call GetLongInt
  117.          jnc >l1
  118.                               ; Falsche Eingabe
  119.          WRITE_STRING error1
  120.          jmp l00              ; Eingabe wiederholen
  121.  
  122. l1:
  123.          push cx,bx           ; 1. Operanden sichern
  124.  
  125. l01:                          ; zweiten Operanden lesen
  126.          WRITE_STRING Prompt3
  127.          mov dx,offset op2
  128.          mov ah,0Ah
  129.          int 021h
  130.          call ShowCR_LF
  131.                               ; Eingabe konvertieren
  132.          mov si,offset op2+2
  133.          call GetLongInt
  134.          jnc >l1
  135.                               ; Falsche Eingabe
  136.          WRITE_STRING error1
  137.          jmp l01              ; Eingabe wiederholen
  138.  
  139. l1:
  140.                               ; 2. Operand steht in CX:BX
  141.          pop ax,dx            ; 1. Operand nach DX:AX
  142.  
  143.          cmp opcode, '+'      ; Opcode auswerten und ausführen
  144.          jne >l1
  145.          call AddLongInt
  146.      clc
  147.          jmp >l2
  148. l1:
  149.          cmp opcode, '-'
  150.          jne >l1
  151.          call SubLongInt
  152.      clc
  153.          jmp >l2
  154. l1:
  155.          cmp opcode,'\'
  156.          jne >l1
  157.          call ModLongInt
  158.          jmp >l2
  159. l1:
  160.          cmp opcode, '/'
  161.          jne >l1
  162.          push ax,bx,cx,dx
  163.          call DivLongInt      ; Ergebnis ermitteln
  164.          jc >l10              ; Fehler beim Dividieren!
  165.          call ShowResult
  166.          pop dx,cx,bx,ax
  167.          call ModLongInt      ; Rest ermitteln
  168.          jc >l2
  169.          call ShowRest
  170.          jmp l0
  171.  
  172. l10:
  173.          pop dx,cx,bx,ax
  174.          jmp >l2
  175.  
  176. l1:
  177.          cmp opcode,'^'
  178.          jne >l1
  179.          call CalcLongIntPotenz
  180.          clc
  181.          jmp >l2
  182. l1:
  183.          call MulLongInt
  184.      clc
  185. l2:
  186.          jnc >l1
  187.                               ; Fehler bei der Berechnung
  188.          WRITE_STRING error2
  189.          jmp >l2
  190.  
  191. l1:                           ; Ergebnis ausgeben
  192.          Call ShowResult
  193. l2:
  194.          jmp l0               ; und nächste Eingabe holen
  195.  
  196. Ende:
  197.          EndProcess 0
  198.  
  199. ; ----------------------------
  200. ; GetLongInt
  201. ;
  202. ; Funktion: Konvertiert die Longint-Variable bei DS:SI nach CX:BX
  203. ;
  204. ; Ausgabe:  CF = 0 -> okay
  205. ;           CF = 1 -> Fehler
  206. ;
  207. GetLongint:
  208.          push bp
  209.          xor bp,bp            ; BP = Vorzeichenmarker
  210.          xor bx,bx
  211.          xor cx,cx            ; CX:BX = Ergebnis -> auf 0 setzen
  212.  
  213.          lodsb                ; AL = erstes Zeichen
  214.          cmp al,'+'
  215.          je >l10              ; + ist Voreinstellung
  216.          cmp al,'-'
  217.          jne >l1
  218.          mov bp,01            ; Marker für negativ setzen
  219. l10:
  220.          lodsb                ; AL = nächstes Zeichen
  221. l1:
  222.          CALL DezDigit?
  223.          jc GetLongIntError
  224.          mov bl,al            ; Ergebnis korrigieren
  225.  
  226. GetLongInt0:
  227.          lodsb                ; AL = nächstes Zeichen
  228.          cmp al,'.'
  229.          je GetLongInt0       ; Punkte als Trenner erlaubt
  230.  
  231.          call DezDigit?
  232.          jc GetLongIntOkay
  233.  
  234.          push ax              ; alten Wert * 10
  235.          mov ax,0Ah
  236.          xor dx,dx
  237.          call MulLongInt
  238.          mov bx,ax
  239.          mov cx,dx
  240.          pop ax
  241.  
  242.          xor ah,ah            ; neue Stelle aufaddieren
  243.          add bx,ax
  244.          adc cx,0
  245.      or cx,cx
  246.          js GetLongIntError
  247.          jmp GetLongInt0      ; und nächstes Zeichen
  248.  
  249. GetLongIntOkay:
  250.          test ch,080h
  251.          jnz GetLongIntError  ; Wert zu groß!
  252.          or bp,bp
  253.          jz GetLongIntOkay1
  254.          call ChangeSignCXBX  ; Vorzeichen ändern
  255.  
  256. GetLongIntOkay1:
  257.          clc
  258.          pop bp
  259.          ret
  260.  
  261. GetLongIntError:
  262.          stc
  263.          pop bp
  264.          ret    
  265.  
  266. ; ----------------------------
  267. ; ShowResult
  268. ;
  269. ; Funktion: Ausgabe des Ergebnisses
  270. ;
  271. ; Eingabe:  DX:AX = Ergebnis
  272. ;
  273. ShowResult:
  274.          push bx
  275.          push cx
  276.          push dx
  277.          push ax
  278.          mov di,offset Result
  279.  
  280.          mov b sign,'+'
  281.          or dx,dx             ; Vorzeichen berücksichtigen
  282.          jns >l1
  283.          call changesigndxax  ; Absolut-Wert ermitteln
  284.          mov b sign,'-'
  285. l1:
  286.  
  287.          mov b v0,0
  288.  
  289.          mov cx,03b9Ah
  290.          mov bx,0CA00h        ; CX:BX = 1.000.000.000
  291.          call StoreDezDigit1
  292.  
  293.          mov cx,05F5h         ; CX:BX = 100.000.000
  294.          mov bx,0E100h
  295.          call StoreDezDigit1
  296.  
  297.          mov cx,098h          ; CX:BX = 10.000.000
  298.          mov bx,09680h
  299.          call StoreDezDigit1
  300.  
  301.          mov cx,0Fh           ; CX:BX = 1.000.000
  302.          mov bx,04240h
  303.          call StoreDezDigit1
  304.  
  305.          mov cx,01h
  306.          mov bx,086A0h        ; CX:BX = 100.000
  307.          call StoreDezDigit1
  308.  
  309.          xor cx,cx            ; CX:BX = 10.000
  310.          mov bx,02710h
  311.          call StoreDezDigit1
  312.  
  313.          xor cx,cx            ; CX:BX = 1.000
  314.          mov bx,03E8h
  315.          call StoreDezDigit1
  316.  
  317.          xor cx,cx            ; CX:BX = 100
  318.          mov bx,064h
  319.          call StoreDezDigit1
  320.  
  321.          xor cx,cx            ; CX:BX = 10
  322.          mov bx,0Ah
  323.          call StoreDezDigit1
  324.  
  325.          mov bx,ax            ; 1er
  326.          cmp v0,0
  327.          if z mov b v0,1
  328.  
  329.          call StoreDezDigit2
  330.                               ; Ergebnis ausgeben
  331.          WRITE_STRING ResultMSG
  332.  
  333.          pop ax
  334.          pop dx
  335.          pop cx
  336.          pop bx
  337.          ret
  338.  
  339. ; ----------------------------
  340. ; ShowRest
  341. ;
  342. ; Funktion: Gibt den Rest einer Division aus
  343. ;
  344. ; Eingabe:  DX:AX = Rest
  345. ;
  346. ShowRest:
  347.          push ax
  348.          push bx
  349.          push cx
  350.          push dx
  351.          mov di,offset Rest
  352.  
  353.          mov b sign,'+'
  354.          or dx,dx             ; Vorzeichen berücksichtigen
  355.          jns >l1
  356.          call changesigndxax  ; Absolut-Wert ermitteln
  357.          mov b sign,'-'
  358. l1:
  359.  
  360.          mov b v0,0
  361.  
  362.          mov cx,03b9Ah
  363.          mov bx,0CA00h        ; CX:BX = 1.000.000.000
  364.          call StoreDezDigit1
  365.  
  366.          mov cx,05F5h         ; CX:BX = 100.000.000
  367.          mov bx,0E100h
  368.          call StoreDezDigit1
  369.  
  370.          mov cx,098h          ; CX:BX = 10.000.000
  371.          mov bx,09680h
  372.          call StoreDezDigit1
  373.  
  374.          mov cx,0Fh           ; CX:BX = 1.000.000
  375.          mov bx,04240h
  376.          call StoreDezDigit1
  377.  
  378.          mov cx,01h
  379.          mov bx,086A0h        ; CX:BX = 100.000
  380.          call StoreDezDigit1
  381.  
  382.          xor cx,cx            ; CX:BX = 10.000
  383.          mov bx,02710h
  384.          call StoreDezDigit1
  385.  
  386.          xor cx,cx            ; CX:BX = 1.000
  387.          mov bx,03E8h
  388.          call StoreDezDigit1
  389.  
  390.          xor cx,cx            ; CX:BX = 100
  391.          mov bx,064h
  392.          call StoreDezDigit1
  393.  
  394.          xor cx,cx            ; CX:BX = 10
  395.          mov bx,0Ah
  396.          call StoreDezDigit1
  397.  
  398.          mov bx,ax            ; 1er
  399.          cmp v0,0
  400.          if z mov b v0,1
  401.  
  402.          call StoreDezDigit2
  403.                               ; Rest ausgeben
  404.          WRITE_STRING RestMSG
  405.          pop dx
  406.          pop cx
  407.          pop bx
  408.          pop ax
  409.          ret
  410.  
  411. ; --------
  412. ; Unteroutine von ShowResult
  413. ;
  414. v0        db  0
  415. sign      db  '+'
  416.  
  417. StoreDezDigit1:
  418.           call DivLongInt     ; Dividieren
  419.                               ; AL = Ergebnis
  420.  
  421. StoreDezDigit2:
  422.          add al,'0'
  423.          cmp v0,2
  424.          je >l1
  425.          cmp v0,1
  426.          je >l00
  427.          cmp al,'0'
  428.          je >l10
  429. l00:
  430.          mov v0,2
  431.          mov ah,sign
  432.          mov [di],ah
  433.          inc di
  434. l1:
  435.          stosb
  436.  
  437.          mov dx,cx
  438.          mov ax,bx            ; Rest nach DX:AX
  439.          ret
  440.  
  441. l10:
  442.          mov al,' '
  443.          jmp l1
  444.  
  445. ; ----------------------------
  446. ; DezDigit?
  447. ;
  448. ; Funktion:  Wandelt das ASCII-Zeichen in AL in dessen binären Wert, falls
  449. ;            es sich um eine Dezimal-Ziffer handelt. Im Fehlerfall wird das
  450. ;            Carry-Flag gesetzt
  451. ;
  452. ; Eingabe:   AL = ASCII-Zeichen
  453. ;
  454. ; Ausgabe:   CF = 0 -> okay, AL = Wert
  455. ;            CF = 1 -> Fehler, AL undefiniert
  456. ;
  457. DezDigit?:
  458.          sub al,'0'
  459.          cmp al,0Ah
  460.          cmc
  461.          ret
  462.  
  463. ; ----------------------------
  464.  
  465.